class Solution:
    def generate(self, numRows: int):

        # 动态规划

        # dp = [[1]*(i + 1) for i in range(numRows)]
        # n = 2
        # while n < numRows:
        #     for i in range(1, len(dp[n]) - 1):
        #         dp[n][i] = dp[n - 1][i - 1] + dp[n - 1][i]
        #     n += 1
        # return dp

        dp = [[1] * (i + 1) for i in range(numRows)]
        if numRows < 2: return dp

        def create(n):
            if n == numRows: return
            for i in range(1, n):
                dp[n][i] = dp[n - 1][i - 1] + dp[n - 1][i]
            create(n + 1)

        create(2)
        return dp
